package com.apes.fn.business.insurance.repository;

import com.apes.fn.business.insurance.modle.InsuranceOrder;
import com.apes.framework.jpa.repository.CustomRepository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;

/**
 * @ClassName : InsuranceOrderRepository
 * @Description : 数据连接层
 * @Author : WSJ
 * @Date: 2020-05-20 17:22
 */
public interface InsuranceOrderRepository extends CustomRepository<InsuranceOrder, String> {
    /**
     * fetch data by company id
     *
     * @param companyId company id
     * @param pageable  page number
     * @param startDate date
     * @param endDate   date
     * @return Page<InsuranceOrder>
     */
    @Query("select t from InsuranceOrder t where t.company.id =?1 and t.createDate>=?2 and t.createDate<?3")
    Page<InsuranceOrder> findByCompany(String companyId, Date startDate, Date endDate, Pageable pageable);

    /**
     * fetch data by company id
     *
     * @param companyId company id
     * @param startDate date
     * @param endDate   date
     * @return List<InsuranceOrder>
     */
    @Query("select t from InsuranceOrder t where t.company.id =?1 and t.createDate>=?2 and t.createDate<?3")
    List<InsuranceOrder> findByCompany(String companyId, Date startDate, Date endDate);
}
